package com.niit.servlet;

import com.niit.pojo.StudentTable;
import com.niit.service.HbaseService;
import com.niit.service.impl.HbaseServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

/**
 * @author 杨铭
 * 2022/2/7,17:20
 */
@WebServlet("/delServlet")
public class delServlet extends HttpServlet {

    public void init(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
    }

    /**
     * 为请求包和相应包初始化
     **/
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //举得例子
        String studentId = req.getParameter("studentId");
        StudentTable studentTable = new StudentTable(studentId, null, null, null, null, null);
        /**
         * 创建学生对象
         * **/
        HbaseService hbaseService = new HbaseServiceImpl();
        hbaseService.delete("Student_Table", studentTable);
        /**
         * 进行删除操作
         * **/
        init(req, resp);
        PrintWriter pw = resp.getWriter();
        pw.write("<h1>当前用户" + studentId + "删除成功</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
